1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.EditableIF;
26 
27 private import glib.Str;
28 private import glib.c.functions;
29 private import gobject.ObjectClass;
30 private import gobject.ObjectG;
31 private import gobject.ParamSpec;
32 private import gobject.Signals;
33 private import gobject.Value;
34 private import gtk.EditableIF;
35 private import gtk.c.functions;
36 public  import gtk.c.types;
37 private import std.algorithm;
38 
39 
40 /**
41  * `GtkEditable` is an interface for text editing widgets.
42  * 
43  * Typical examples of editable widgets are [class@Gtk.Entry] and
44  * [class@Gtk.SpinButton]. It contains functions for generically manipulating
45  * an editable widget, a large number of action signals used for key bindings,
46  * and several signals that an application can connect to modify the behavior
47  * of a widget.
48  * 
49  * As an example of the latter usage, by connecting the following handler to
50  * [signal@Gtk.Editable::insert-text], an application can convert all entry
51  * into a widget into uppercase.
52  * 
53  * ## Forcing entry to uppercase.
54  * 
55  * ```c
56  * #include <ctype.h>
57  * 
58  * void
59  * insert_text_handler (GtkEditable *editable,
60  * const char  *text,
61  * int          length,
62  * int         *position,
63  * gpointer     data)
64  * {
65  * char *result = g_utf8_strup (text, length);
66  * 
67  * g_signal_handlers_block_by_func (editable,
68  * (gpointer) insert_text_handler, data);
69  * gtk_editable_insert_text (editable, result, length, position);
70  * g_signal_handlers_unblock_by_func (editable,
71  * (gpointer) insert_text_handler, data);
72  * 
73  * g_signal_stop_emission_by_name (editable, "insert_text");
74  * 
75  * g_free (result);
76  * }
77  * ```
78  * 
79  * ## Implementing GtkEditable
80  * 
81  * The most likely scenario for implementing `GtkEditable` on your own widget
82  * is that you will embed a `GtkText` inside a complex widget, and want to
83  * delegate the editable functionality to that text widget. `GtkEditable`
84  * provides some utility functions to make this easy.
85  * 
86  * In your class_init function, call [func@Gtk.Editable.install_properties],
87  * passing the first available property ID:
88  * 
89  * ```c
90  * static void
91  * my_class_init (MyClass *class)
92  * {
93  * ...
94  * g_object_class_install_properties (object_class, NUM_PROPERTIES, props);
95  * gtk_editable_install_properties (object_clas, NUM_PROPERTIES);
96  * ...
97  * }
98  * ```
99  * 
100  * In your interface_init function for the `GtkEditable` interface, provide
101  * an implementation for the get_delegate vfunc that returns your text widget:
102  * 
103  * ```c
104  * GtkEditable *
105  * get_editable_delegate (GtkEditable *editable)
106  * {
107  * return GTK_EDITABLE (MY_WIDGET (editable)->text_widget);
108  * }
109  * 
110  * static void
111  * my_editable_init (GtkEditableInterface *iface)
112  * {
113  * iface->get_delegate = get_editable_delegate;
114  * }
115  * ```
116  * 
117  * You don't need to provide any other vfuncs. The default implementations
118  * work by forwarding to the delegate that the GtkEditableInterface.get_delegate()
119  * vfunc returns.
120  * 
121  * In your instance_init function, create your text widget, and then call
122  * [method@Gtk.Editable.init_delegate]:
123  * 
124  * ```c
125  * static void
126  * my_widget_init (MyWidget *self)
127  * {
128  * ...
129  * self->text_widget = gtk_text_new ();
130  * gtk_editable_init_delegate (GTK_EDITABLE (self));
131  * ...
132  * }
133  * ```
134  * 
135  * In your dispose function, call [method@Gtk.Editable.finish_delegate] before
136  * destroying your text widget:
137  * 
138  * ```c
139  * static void
140  * my_widget_dispose (GObject *object)
141  * {
142  * ...
143  * gtk_editable_finish_delegate (GTK_EDITABLE (self));
144  * g_clear_pointer (&self->text_widget, gtk_widget_unparent);
145  * ...
146  * }
147  * ```
148  * 
149  * Finally, use [func@Gtk.Editable.delegate_set_property] in your `set_property`
150  * function (and similar for `get_property`), to set the editable properties:
151  * 
152  * ```c
153  * ...
154  * if (gtk_editable_delegate_set_property (object, prop_id, value, pspec))
155  * return;
156  * 
157  * switch (prop_id)
158  * ...
159  * ```
160  * 
161  * It is important to note that if you create a `GtkEditable` that uses
162  * a delegate, the low level [signal@Gtk.Editable::insert-text] and
163  * [signal@Gtk.Editable::delete-text] signals will be propagated from the
164  * "wrapper" editable to the delegate, but they will not be propagated from
165  * the delegate to the "wrapper" editable, as they would cause an infinite
166  * recursion. If you wish to connect to the [signal@Gtk.Editable::insert-text]
167  * and [signal@Gtk.Editable::delete-text] signals, you will need to connect
168  * to them on the delegate obtained via [method@Gtk.Editable.get_delegate].
169  */
170 public interface EditableIF{
171 	/** Get the main Gtk struct */
172 	public GtkEditable* getEditableStruct(bool transferOwnership = false);
173 
174 	/** the main Gtk struct as a void* */
175 	protected void* getStruct();
176 
177 
178 	/** */
179 	public static GType getType()
180 	{
181 		return gtk_editable_get_type();
182 	}
183 
184 	/**
185 	 * Gets a property of the `GtkEditable` delegate for @object.
186 	 *
187 	 * This is helper function that should be called in the `get_property`
188 	 * function of your `GtkEditable` implementation, before handling your
189 	 * own properties.
190 	 *
191 	 * Params:
192 	 *     object = a `GObject`
193 	 *     propId = a property ID
194 	 *     value = value to set
195 	 *     pspec = the `GParamSpec` for the property
196 	 *
197 	 * Returns: %TRUE if the property was found
198 	 */
199 	public static bool delegateGetProperty(ObjectG object, uint propId, Value value, ParamSpec pspec)
200 	{
201 		return gtk_editable_delegate_get_property((object is null) ? null : object.getObjectGStruct(), propId, (value is null) ? null : value.getValueStruct(), (pspec is null) ? null : pspec.getParamSpecStruct()) != 0;
202 	}
203 
204 	/**
205 	 * Sets a property on the `GtkEditable` delegate for @object.
206 	 *
207 	 * This is a helper function that should be called in the `set_property`
208 	 * function of your `GtkEditable` implementation, before handling your
209 	 * own properties.
210 	 *
211 	 * Params:
212 	 *     object = a `GObject`
213 	 *     propId = a property ID
214 	 *     value = value to set
215 	 *     pspec = the `GParamSpec` for the property
216 	 *
217 	 * Returns: %TRUE if the property was found
218 	 */
219 	public static bool delegateSetProperty(ObjectG object, uint propId, Value value, ParamSpec pspec)
220 	{
221 		return gtk_editable_delegate_set_property((object is null) ? null : object.getObjectGStruct(), propId, (value is null) ? null : value.getValueStruct(), (pspec is null) ? null : pspec.getParamSpecStruct()) != 0;
222 	}
223 
224 	/**
225 	 * Overrides the `GtkEditable` properties for @class.
226 	 *
227 	 * This is a helper function that should be called in class_init,
228 	 * after installing your own properties.
229 	 *
230 	 * Note that your class must have "text", "cursor-position",
231 	 * "selection-bound", "editable", "width-chars", "max-width-chars",
232 	 * "xalign" and "enable-undo" properties for this function to work.
233 	 *
234 	 * To handle the properties in your set_property and get_property
235 	 * functions, you can either use [func@Gtk.Editable.delegate_set_property]
236 	 * and [func@Gtk.Editable.delegate_get_property] (if you are using
237 	 * a delegate), or remember the @first_prop offset and add it to the
238 	 * values in the [enum@Gtk.EditableProperties] enumeration to get the
239 	 * property IDs for these properties.
240 	 *
241 	 * Params:
242 	 *     objectClass = a `GObjectClass`
243 	 *     firstProp = property ID to use for the first property
244 	 *
245 	 * Returns: the number of properties that were installed
246 	 */
247 	public static uint installProperties(ObjectClass objectClass, uint firstProp)
248 	{
249 		return gtk_editable_install_properties((objectClass is null) ? null : objectClass.getObjectClassStruct(), firstProp);
250 	}
251 
252 	/**
253 	 * Deletes the currently selected text of the editable.
254 	 *
255 	 * This call doesn’t do anything if there is no selected text.
256 	 */
257 	public void deleteSelection();
258 
259 	/**
260 	 * Deletes a sequence of characters.
261 	 *
262 	 * The characters that are deleted are those characters at positions
263 	 * from @start_pos up to, but not including @end_pos. If @end_pos is
264 	 * negative, then the characters deleted are those from @start_pos to
265 	 * the end of the text.
266 	 *
267 	 * Note that the positions are specified in characters, not bytes.
268 	 *
269 	 * Params:
270 	 *     startPos = start position
271 	 *     endPos = end position
272 	 */
273 	public void deleteText(int startPos, int endPos);
274 
275 	/**
276 	 * Undoes the setup done by [method@Gtk.Editable.init_delegate].
277 	 *
278 	 * This is a helper function that should be called from dispose,
279 	 * before removing the delegate object.
280 	 */
281 	public void finishDelegate();
282 
283 	/**
284 	 * Gets the alignment of the editable.
285 	 *
286 	 * Returns: the alignment
287 	 */
288 	public float getAlignment();
289 
290 	/**
291 	 * Retrieves a sequence of characters.
292 	 *
293 	 * The characters that are retrieved are those characters at positions
294 	 * from @start_pos up to, but not including @end_pos. If @end_pos is negative,
295 	 * then the characters retrieved are those characters from @start_pos to
296 	 * the end of the text.
297 	 *
298 	 * Note that positions are specified in characters, not bytes.
299 	 *
300 	 * Params:
301 	 *     startPos = start of text
302 	 *     endPos = end of text
303 	 *
304 	 * Returns: a pointer to the contents of the widget as a
305 	 *     string. This string is allocated by the `GtkEditable` implementation
306 	 *     and should be freed by the caller.
307 	 */
308 	public string getChars(int startPos, int endPos);
309 
310 	/**
311 	 * Gets the `GtkEditable` that @editable is delegating its
312 	 * implementation to.
313 	 *
314 	 * Typically, the delegate is a [class@Gtk.Text] widget.
315 	 *
316 	 * Returns: the delegate `GtkEditable`
317 	 */
318 	public EditableIF getDelegate();
319 
320 	/**
321 	 * Retrieves whether @editable is editable.
322 	 *
323 	 * Returns: %TRUE if @editable is editable.
324 	 */
325 	public bool getEditable();
326 
327 	/**
328 	 * Gets if undo/redo actions are enabled for @editable
329 	 *
330 	 * Returns: %TRUE if undo is enabled
331 	 */
332 	public bool getEnableUndo();
333 
334 	/**
335 	 * Retrieves the desired maximum width of @editable, in characters.
336 	 *
337 	 * Returns: the maximum width of the entry, in characters
338 	 */
339 	public int getMaxWidthChars();
340 
341 	/**
342 	 * Retrieves the current position of the cursor relative
343 	 * to the start of the content of the editable.
344 	 *
345 	 * Note that this position is in characters, not in bytes.
346 	 *
347 	 * Returns: the cursor position
348 	 */
349 	public int getPosition();
350 
351 	/**
352 	 * Retrieves the selection bound of the editable.
353 	 *
354 	 * @start_pos will be filled with the start of the selection and
355 	 * @end_pos with end. If no text was selected both will be identical
356 	 * and %FALSE will be returned.
357 	 *
358 	 * Note that positions are specified in characters, not bytes.
359 	 *
360 	 * Params:
361 	 *     startPos = location to store the starting position
362 	 *     endPos = location to store the end position
363 	 *
364 	 * Returns: %TRUE if there is a non-empty selection, %FALSE otherwise
365 	 */
366 	public bool getSelectionBounds(out int startPos, out int endPos);
367 
368 	/**
369 	 * Retrieves the contents of @editable.
370 	 *
371 	 * The returned string is owned by GTK and must not be modified or freed.
372 	 *
373 	 * Returns: a pointer to the contents of the editable
374 	 */
375 	public string getText();
376 
377 	/**
378 	 * Gets the number of characters of space reserved
379 	 * for the contents of the editable.
380 	 *
381 	 * Returns: number of chars to request space for, or negative if unset
382 	 */
383 	public int getWidthChars();
384 
385 	/**
386 	 * Sets up a delegate for `GtkEditable`.
387 	 *
388 	 * This is assuming that the get_delegate vfunc in the `GtkEditable`
389 	 * interface has been set up for the @editable's type.
390 	 *
391 	 * This is a helper function that should be called in instance init,
392 	 * after creating the delegate object.
393 	 */
394 	public void initDelegate();
395 
396 	/**
397 	 * Inserts @length bytes of @text into the contents of the
398 	 * widget, at position @position.
399 	 *
400 	 * Note that the position is in characters, not in bytes.
401 	 * The function updates @position to point after the newly
402 	 * inserted text.
403 	 *
404 	 * Params:
405 	 *     text = the text to append
406 	 *     length = the length of the text in bytes, or -1
407 	 *     position = location of the position text will be inserted at
408 	 */
409 	public void insertText(string text, int length, ref int position);
410 
411 	/**
412 	 * Selects a region of text.
413 	 *
414 	 * The characters that are selected are those characters at positions
415 	 * from @start_pos up to, but not including @end_pos. If @end_pos is
416 	 * negative, then the characters selected are those characters from
417 	 * @start_pos to  the end of the text.
418 	 *
419 	 * Note that positions are specified in characters, not bytes.
420 	 *
421 	 * Params:
422 	 *     startPos = start of region
423 	 *     endPos = end of region
424 	 */
425 	public void selectRegion(int startPos, int endPos);
426 
427 	/**
428 	 * Sets the alignment for the contents of the editable.
429 	 *
430 	 * This controls the horizontal positioning of the contents when
431 	 * the displayed text is shorter than the width of the editable.
432 	 *
433 	 * Params:
434 	 *     xalign = The horizontal alignment, from 0 (left) to 1 (right).
435 	 *         Reversed for RTL layouts
436 	 */
437 	public void setAlignment(float xalign);
438 
439 	/**
440 	 * Determines if the user can edit the text in the editable widget.
441 	 *
442 	 * Params:
443 	 *     isEditable = %TRUE if the user is allowed to edit the text
444 	 *         in the widget
445 	 */
446 	public void setEditable(bool isEditable);
447 
448 	/**
449 	 * If enabled, changes to @editable will be saved for undo/redo
450 	 * actions.
451 	 *
452 	 * This results in an additional copy of text changes and are not
453 	 * stored in secure memory. As such, undo is forcefully disabled
454 	 * when [property@Gtk.Text:visibility] is set to %FALSE.
455 	 *
456 	 * Params:
457 	 *     enableUndo = if undo/redo should be enabled
458 	 */
459 	public void setEnableUndo(bool enableUndo);
460 
461 	/**
462 	 * Sets the desired maximum width in characters of @editable.
463 	 *
464 	 * Params:
465 	 *     nChars = the new desired maximum width, in characters
466 	 */
467 	public void setMaxWidthChars(int nChars);
468 
469 	/**
470 	 * Sets the cursor position in the editable to the given value.
471 	 *
472 	 * The cursor is displayed before the character with the given (base 0)
473 	 * index in the contents of the editable. The value must be less than
474 	 * or equal to the number of characters in the editable. A value of -1
475 	 * indicates that the position should be set after the last character
476 	 * of the editable. Note that @position is in characters, not in bytes.
477 	 *
478 	 * Params:
479 	 *     position = the position of the cursor
480 	 */
481 	public void setPosition(int position);
482 
483 	/**
484 	 * Sets the text in the editable to the given value.
485 	 *
486 	 * This is replacing the current contents.
487 	 *
488 	 * Params:
489 	 *     text = the text to set
490 	 */
491 	public void setText(string text);
492 
493 	/**
494 	 * Changes the size request of the editable to be about the
495 	 * right size for @n_chars characters.
496 	 *
497 	 * Note that it changes the size request, the size can still
498 	 * be affected by how you pack the widget into containers.
499 	 * If @n_chars is -1, the size reverts to the default size.
500 	 *
501 	 * Params:
502 	 *     nChars = width in chars
503 	 */
504 	public void setWidthChars(int nChars);
505 
506 	/**
507 	 * Emitted at the end of a single user-visible operation on the
508 	 * contents.
509 	 *
510 	 * E.g., a paste operation that replaces the contents of the
511 	 * selection will cause only one signal emission (even though it
512 	 * is implemented by first deleting the selection, then inserting
513 	 * the new content, and may cause multiple ::notify::text signals
514 	 * to be emitted).
515 	 */
516 	gulong addOnChanged(void delegate(EditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0);
517 
518 	/**
519 	 * Emitted when text is deleted from the widget by the user.
520 	 *
521 	 * The default handler for this signal will normally be responsible for
522 	 * deleting the text, so by connecting to this signal and then stopping
523 	 * the signal with g_signal_stop_emission(), it is possible to modify the
524 	 * range of deleted text, or prevent it from being deleted entirely.
525 	 *
526 	 * The @start_pos and @end_pos parameters are interpreted as for
527 	 * [method@Gtk.Editable.delete_text].
528 	 *
529 	 * Params:
530 	 *     startPos = the starting position
531 	 *     endPos = the end position
532 	 */
533 	gulong addOnDeleteText(void delegate(int, int, EditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0);
534 
535 	/**
536 	 * Emitted when text is inserted into the widget by the user.
537 	 *
538 	 * The default handler for this signal will normally be responsible
539 	 * for inserting the text, so by connecting to this signal and then
540 	 * stopping the signal with g_signal_stop_emission(), it is possible
541 	 * to modify the inserted text, or prevent it from being inserted entirely.
542 	 *
543 	 * Params:
544 	 *     text = the new text to insert
545 	 *     length = the length of the new text, in bytes,
546 	 *         or -1 if new_text is nul-terminated
547 	 *     position = the position, in characters,
548 	 *         at which to insert the new text. this is an in-out
549 	 *         parameter.  After the signal emission is finished, it
550 	 *         should point after the newly inserted text.
551 	 */
552 	gulong addOnInsertText(void delegate(string, int, void*, EditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0);
553 }